﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Excell_On_Services.ViewModels;
using Excell_On_Services.Models;

namespace Excell_On_Services.Controllers
{
    //controller for back - end
    public class BEClientController : Controller
    {
        ////
        //// GET: /BEClient/

        //public ActionResult Index()
        //{
        //    return View();
        //}

        //
        // GET: /BEClient/Details/5




        public IEOSRepository Repository { get; set; }

        public BEClientController() :this (new EFEOSRepository())
        {

        }

        public BEClientController(IEOSRepository repository)
        {
            Repository = repository;
        }


        public ActionResult Details(Guid id)
        {
            var client = Repository.FindClientsByID(id);
            var model = new ClientModel
            {
                ClientID = client.ClientID,
                CompanyName = client.CompanyName,
                Description = client.Description,
                ProductDescription = client.Product_Description,
                Address = client.Address,
                Phone = client.Phone,
            };
            return View(model);
        }

        //
        // GET: /BEClient/Create

        public ActionResult Create()
        {
            
            return View();
        } 

        //
        // POST: /BEClient/Create

        //[HttpPost]
        //public ActionResult Create(ClientModel model)
        //{
        //    try
        //    {
        //        // TODO: Add insert logic here
        //        if (!ModelState.IsValid)
        //            return View(model);
        //        var client = new Client
        //        {
        //            CompanyName = model.CompanyName,
        //            Address = model.Address,
        //            Phone = model.Phone,
        //            Email = model.Email,
        //            Description = model.Description,
        //            isLock = model.IsLock,
        //            Product_Description = model.ProductDescription
        //        };
        //        Repository.AddClient(client);
        //        Repository.CommitChanges();
        //        return RedirectToAction("Details", new { id = client.ClientID });
        //    }
        //    catch
        //    {
        //        return View();
        //    }
        //}
        
        //
        // GET: /BEClient/Edit/5

        //public ActionResult Edit(Guid id)
        //{
        //    var client = Repository.FindClientsByID(id);
        //    var model = new ClientModel
        //    {
        //        ClientID = client.ClientID,
        //        CompanyName = client.CompanyName,
        //        Address = client.Address,
        //        Email = client.Email,
        //        Phone = client.Phone,
        //        Description = client.Description,
        //        ProductDescription = client.Product_Description
        //    };
        //    return View(model);
        //}

        //
        // POST: /BEClient/Edit/5

        //[HttpPost]
        //public ActionResult Edit(int id, ClientModel model)
        //{
        //    try
        //    {
        //        if (!ModelState.IsValid)
        //            return View(model);
        //        var item = Repository.FindClientsByID(model.ClientID);
        //        item.CompanyName = model.CompanyName;
        //        item.Description = model.Description;
        //        item.Product_Description = model.ProductDescription;
        //        item.Phone = model.Phone;
        //        item.Email = model.Email;
        //        item.Address = model.Address;
        //        Repository.CommitChanges();
        //        return RedirectToAction("Details", new { id = item.ClientID });
        //    }
        //    catch (Exception ex)
        //    {
        //        return View();
        //    }
        //}

    }
}
